package com.mesnac.comm.util;

import java.io.File;
import java.io.FileNotFoundException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;


public class XMLTools {

	private static Log logger = LogFactory.getLog(XMLTools.class);
	private Element root = null;
	private Document doc = null;
	public Element getRoot() {
		return root;
	}
	public void setRoot(Element root) {
		this.root = root;
	}
	public Document getDoc() {
		return doc;
	}
	public void setDoc(Document doc) {
		this.doc = doc;
	}
	/**
	 * 
	* <p>Title: </p>
	* <p>Description: </p>加载相应的xml文件
	* @param filePath
	* @throws FileNotFoundException
	* @throws DocumentException
	 */
	public XMLTools(String filePath) throws FileNotFoundException,DocumentException{
		SAXReader saxReader = new SAXReader();
		File xmlFile = new File(filePath);
		
		if(!xmlFile.exists()){
			throw new FileNotFoundException(filePath+"not found");
		}
		try{
			
			doc = saxReader.read(xmlFile);
		}catch(DocumentException e){
			e.printStackTrace();
			logger.debug(e);
			throw e;
		}
		root = doc.getRootElement();
		
	}
	
	public void close(){
		root = null;
		doc = null;
	}
	
	
	
}
